<template>
  <div class="box">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item to="/login" replace>首页</el-breadcrumb-item>
      <el-breadcrumb-item>平台运营</el-breadcrumb-item>
      <el-breadcrumb-item>首页轮播图</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="tableBox">
      <div class="tableTitle">首页轮播图</div>
      <div class="searchBox">
        <el-form :model="searchObject" size="mini" inline>
          <div class="block">
            <el-form-item>
              <el-button icon="el-icon-circle-plus" type="primary" @click="addMap">添加</el-button>
            </el-form-item>
          </div>
          <div class="block">
            <el-form-item label="区域选择">
              <regionSelect @onChangeArea="onChangeArea"></regionSelect>
            </el-form-item>
            <el-form-item>
              <el-radio-group v-model="searchObject.resource">
                <el-radio label="1">在用</el-radio>
                <el-radio label="2">不在用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" circle @click="search"></el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <el-table :data="tableData">
        <el-table-column prop="" label="编号" align="center"></el-table-column>
        <el-table-column label="图片" align="center">
          <template slot-scope="data">
            <img :src="data.row.url" alt="">
          </template>
        </el-table-column>
        <el-table-column prop="" label="图片类型" align="center"></el-table-column>
        <el-table-column prop="" label="跳转商家ID或者理财ID" align="center"></el-table-column>
        <el-table-column prop="" label="图片修改时间" align="center"></el-table-column>
        <el-table-column prop="" label="排序" align="center"></el-table-column>
        <el-table-column prop="" label="状态" align="center"></el-table-column>
        <el-table-column prop="" label="区域" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="data">
            <span class="colors">废弃</span>
          </template>
        </el-table-column>
        <el-table-column label="修改" align="center">
          <template slot-scope="data">
            <span class="colors">修改</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="addMap" v-if="addMapShow">
        <div class="upload clearFix">
          <el-upload class="upload-demo" :show-file-list="false" drag
                     action="https://jsonplaceholder.typicode.com/posts/"
                     :on-success="handleSuccess" :before-upload="beforeAvatarUpload">
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          </el-upload>
          <div class="img">
            <img :src="option.imageUrl" alt="">
          </div>
        </div>
        <el-form :model="option" size="mini" label-width="160px">
          <el-form-item label="图片上传返回地址">
            <el-input v-model="option.imageUrl"></el-input>
            <span>用于图片的展示</span>
          </el-form-item>
          <el-form-item label="图片外部链接地址">
            <el-input v-model="option.imageUrl"></el-input>
            <span>跳转其他页面url</span>
          </el-form-item>
          <el-form-item label="跳转商家ID或者理财ID">
            <el-input v-model="option.imageUrl"></el-input>
            <span>跳转其他页面url</span>
          </el-form-item>
          <el-form-item label="图片的排序">
            <el-input v-model="option.imageUrl"></el-input>
            <span>跳转其他页面url</span>
          </el-form-item>
          <el-form-item label="跳转类型">
            <el-select v-model="option.linkType" placeholder="请选择">
              <el-option v-for="item in typeOptions" :key="item.value" :label="item.label"
                         :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="地区">
            <regionSelect @onChangeAreas="onChangeArea"></regionSelect>
          </el-form-item>
          <el-form-item>
            <el-button type="primary">提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import regionSelect from 'components/regionSelect'

  export default {
    data () {
      return {
        searchObject: {
          resource: '1',
          linkType: ''
        },
        tableData: [],
        option: {
          imageUrl: ''
        },
        typeOptions: [],
        addMapShow: false
      }
    },
    created () {
    },
    methods: {
      search () {
      },
      onChangeArea (val) {
      },
      handleSuccess (res, file) {
        this.option.imageUrl = URL.createObjectURL(file.raw)
      },
      beforeAvatarUpload (file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!')
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!')
        }
        return isJPG && isLt2M
      },
      addMap () {
        this.addMapShow = !this.addMapShow
      }
    },
    components: {
      regionSelect
    }
  }
</script>

<style lang="less" ref="stylesheet/less" scoped>
  .addMap {
    padding: 20px;

    .upload {
      text-align: center;

      .upload-demo {
        float: left;
        width: 50%;
      }

      .img {
        float: right;
        width: 50%;

        img {
          width: 358px;
          height: 178px;
          border: 1px dashed #d9d9d9;
        }
      }
    }

    .el-form {
      margin: 20px auto 0;
      width: 60%;

      .el-input {
        width: 70%;
      }
    }
  }
</style>
